//
// Author: Vladimir Migashko <migashko@gmail.com>, (C) 2011
//
// Copyright: See COPYING file that comes with this distribution
//

#ifndef FASYS_CHANNELS_MESSAGES_CHANNELS_HPP
#define FASYS_CHANNELS_MESSAGES_CHANNELS_HPP

#include "types.hpp"
//#include "message.hpp"

// #include <list>

namespace fasys{ namespace channels{

class messages_channels_container;
class channels_container;

class messages_channels
{
public:
  // typedef std::list<message> message_list;
  virtual ~messages_channels();
  messages_channels();
  messages_channels(channels_container* channels);
protected:
  messages_channels( const messages_channels& mc);

public:
  // return true - есть подписчики
  channel_id_t create(const std::string& channel, size_t min_size = FASYS_MIN_CHANNEL_SIZE, size_t max_size = FASYS_MAX_CHANNEL_SIZE );
  bool publish(message_publish& mp, message_notify& mn);
  bool update(const message_notify& mn);
  bool update(const message_list_response& mn);
//  void query(message_list& ml);
  // Просто помечаем что есть подписчики 
  channel_id_t subscribe( const std::string& name, time_t timeout );
  bool subscribe( subscribe_request& srq, subscribe_response& srs );

  void query( message_list_request& mlrq, message_list_response& mlrs) const;

  // Извлечь сообщения канала
  void detach( message_list_request& mlrq, message_list_response& mlrs);
private:
  messages_channels_container* _messages;
  channels_container* _channels;
  bool _owner_channels;
};

}}

#endif
